#include "factory.h"

bool Factory::addEntityClass(Entity newClass)
{
	String newType = newClass.getType();
	if (m_classes.find(newType) != m_classes.end()) {
		std::cerr << "Error: cannot add class '" << newType
				<< "', class name already used" << std::endl;
		return false;
	}

	m_classes[newType] = newClass;
	return true;
	
}

Entity& Factory::getEntityClass(String sType)
{
	// add error checking?
	return m_classes[sType];
}

Entity* Factory::instantiateEntity(String sType)
{
	return instantiateEntity(sType, "generate name here");
}

Entity* Factory::instantiateEntity(String sType, String sName)
{
	// TODO: check for same name
	
	//Entity* pNewEntity = getEntityClass(sType)
	
	Entity* newObject = getEntityClass(sType).clone();
	newObject->getVar<String>("name") = sName;
	std::cout << "name: " << newObject->getVar<String>("name") << std::endl;
	m_pObjects[sName] = newObject;
	return newObject;
}

Entity* Factory::getEntity(String sName)
{
	// add error checking?
	return m_pObjects[sName];
}


